{%extends file="base_content.html"%}
{%block name="breadcrumb"%}
<li><a href="index.php?c=sys_module">模块管理</a></li>
<li class="active">编辑</li>
{%/block%}

{%block name="content"%}

<h3 class="lighter block green">输入模块信息</h3>

<form class="form-horizontal" id="validation-form" method="post" role="form">
    {%include file="inc_form_result.html"%}
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="module_name">模块名称:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="module_name" id="module_name" class="col-xs-12 col-sm-6"
                       value="{%$entity.module_name|default:''%}" />
            </div>
        </div>
    </div>
    <div class="form-group {%if !empty($smarty.request.parent_id)%}hidden{%/if%}">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="module_icon">模块图标:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="module_icon" id="module_icon" class="col-xs-12 col-sm-6"
                       value="{%$entity.module_icon|default:''%}" />
            </div>
        </div>
    </div>

    <div class="form-group {%if empty($smarty.request.parent_id)%}hidden{%/if%}">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="module_resource">模块地址:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="module_resource" id="module_resource" class="col-xs-12 col-sm-6"
                       value="{%$entity.module_resource|default:''%}" />
            </div>
        </div>
    </div>

        <input type="hidden" name="module_type" value="{%$smarty.request.module_type|default:'module'%}">

    <input type="hidden" name="module_parent_id" value="{%$smarty.request.parent_id|default:''%}">
    <div class="clearfix form-actions">
        <div class="col-md-offset-3 col-md-9">
            <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                提交
            </button>

            &nbsp; &nbsp; &nbsp;
            <a class="btn" href="index.php?c=sys_module">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                返回
            </a>
        </div>
    </div>
</form>


{%/block%}

{%block name="js"%}
<script>
      $(function(){


          $('#validation-form').validate({
              errorElement: 'div',
              errorClass: 'help-block',
              focusInvalid: false,
              rules: {

                  module_name: {
                      required: true,
                      minlength: 3,
                      maxlength: 15
                  }

              },

              messages: {

                  module_name: {
                      required: "请输入模块名",
                      minlength: "模块名需要3-15个字符",
                      maxlength: "模块名需要3-15个字符"
                  }
              },



              highlight: function (e) {
                  $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
              },

              success: function (e) {
                  $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                  $(e).remove();
              },

              errorPlacement: function (error, element) {
                  if(element.is(':checkbox') || element.is(':radio')) {
                      var controls = element.closest('div[class*="col-"]');
                      if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                      else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                  }
                  else if(element.is('.select2')) {
                      error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                  }
                  else if(element.is('.chosen-select')) {
                      error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                  }
                  else error.insertAfter(element.parent());
              }


          });
      });
</script>
{%/block%}